//
// Created by fanghr on 17-12-23.
//

#ifndef PROJECT_IMU_ACCELERATION_H
#define PROJECT_IMU_ACCELERATION_H

#include "../../include.h"

class imu_acceleration {
public:
    struct table_t {
        friend class boost::serialization::access;

        int16_t ax, ay, az, t;

        template<class Archive>
        void serialize(Archive &ar, const unsigned int) {
            ar & ax;
            ar & ay;
            ar & az;
            ar & t;
        }
    };

private:
    friend class boost::serialization::access;

    template<class Archive>
    void serialize(Archive &ar, const unsigned int) {
        ar & table;
    }

    table_t table;
    const static int16_t g = 9.8;
public:
    imu_acceleration() {}

    imu_acceleration(boost::array<uint8_t, 9> raw) {
        table.ax = (int16_t) (((int16_t) raw.at(1) << 8) | raw.at(0)) / (uint16_t) 32768 * (uint16_t) 16 * g;
        table.ay = (int16_t) (((int16_t) raw.at(3) << 8) | raw.at(2)) / (uint16_t) 32768 * (uint16_t) 16 * g;
        table.az = (int16_t) (((int16_t) raw.at(5) << 8) | raw.at(4)) / (uint16_t) 32768 * (uint16_t) 16 * g;
        table.t = (int16_t) (((int16_t) raw.at(7) << 8) | raw.at(6)) / (uint16_t) 100;
    }

    table_t get() {
        return table;
    }
};

#endif //PROJECT_IMU_ACCELERATION_H
